<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>教案列表</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>

<div class="layui-row">
    <form class="layui-form layui-col-md12 x-so" onsubmit="return false">
        <!--<input class="layui-input" placeholder="开始日" name="start" id="start">-->
        <!--<input class="layui-input" placeholder="截止日" name="end" id="end">-->
        <input type="text" name="motion"  placeholder="运动项目" autocomplete="off" class="layui-input">
        <button class="layui-btn"  id="search"><i class="layui-icon">&#xe615;</i></button>
    </form>
</div>
<xblock>
    <button class="layui-btn" id="add"><i class="layui-icon"></i>添加教案</button>
</xblock>
<table id="planList">

</table>
</body>
<script>
    $('#planList').bootstrapTable({
        //获取行号
        language: 'zh-CN',
        todayHighlight: true,
        striped: true,//设置为 true 会有隔行变色效果
        method: 'post',//服务器数据的请求方式 'get' or 'post'
        url: "{:url('/plan/getPlanInfo')}",//服务器数据的加载地址
        toolbar:'#toolbar',//
        searchOnEnterKey:true,
        sortName:'id',//排序字段
        sortOrder : 'desc',//降序
        sidePagination: "server",   //分页方式：client客户端分页，server服务端分页（*）
        pagination: 'false',//设置为 true 会在表格底部显示分页条
        clickToSelect:'true',//设置true 将在点击行时，自动选择rediobox 和 checkbox
        singleSelect:'true',//设置True 将禁止多选
        pageSize: '15',//如果设置了分页，页面数据条数
        pageList:[15,30,50],
        smartDisplay:false,
        //得到查询的参数
        queryParams : function (params) {
            //这里的键的名字和控制器的变量名必须一直，这边改动，控制器也需要改成一样的
            var temp = {
                rows: params.limit,                         //页面大小
                page: (params.offset / params.limit) + 1,   //页码
                sort: params.sort,      //排序列名
                sortOrder: params.order,//排位命令（desc，asc）
                searchName:$("input[name=motion]").val()
            };
            return temp;
        },
        columns: [
            //                {title:'请选择',align:'center',checkbox : true},
            {field: 'id', title: 'ID', align:'center'},
            {field: 'motion', title: '运动项目', align:'center'},
//            {title: '所属类别', align:'center',formatter:type},
//            {field: 'textbook_analysis', title: '教材分析', align:'center'},
//            {field: 'teaching', title: '教法与学法', align:'center'},
//            {field: 'objective', title: '教学目的', align:'center'},
//            {field: 'contents',title: '教学内容', align:'center'},
//            {field: 'equipment',title: '场地器材', align:'center'},
//            {field: 'target',title: '教学目标', align:'center'},
//            {field: 'load_target',title: '负荷目标', align:'center'},
//            {field: 'teaching_emphasis',title: '教学重点', align:'center'},
//            {field: 'difficulty',title: '教学难点', align:'center'},
//            {field: 'start_part',title: '开始部分', align:'center'},
//            {field: 'preparation_part',title: '准备部分', align:'center'},
//            {field: 'basic_part',title: '基本部分', align:'center'},
//            {field: 'end_part',title: '结束部分', align:'center'},
//            {field: 'security',title: '安全措施', align:'center'},
            {align:'center', title:'操作', formatter:operateFormatter}
        ]}
    );
    //操作按钮
    function operateFormatter(val,rows) {
        return [
            "<button type='button' onclick='edit("+rows.id+")' class='btn btn-primary btn-xs'>修改</button>&nbsp;&nbsp;",
            "<button type='button' onclick='del("+rows.id+")' class='btn btn-danger btn-xs'>删除</button>&nbsp;&nbsp;"
        ].join('');
    }
    //类别
    function type(val,rows){
        if(rows.type){
            return rows.type.title;
        }
    }
    //检索
    $("#search").click(function(){
        $("#planList").bootstrapTable(('refresh'));
    });
    //删除
    function del(id){
        layer.confirm('你确定要删除吗',{btn:['确定','取消']},function(){
            $.ajax({
                url:"{:url('/plan/planDelete')}",
                data:{
                    id:id
                },
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            $("#planList").bootstrapTable(('refresh'));
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }
            });
        });
    }
    //编辑
    function edit(id){
        window.location.href = "{:url('/moonlighting_plan/edit')}?id="+id;
    }
</script>
<script>
    $("#add").click(function(){
        window.location.href = "{:url('/moonlighting_plan/add')}";
    });
</script>
</html>